package com.htyy.yutao.BottomNavigationViewPage;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dingmouren.layoutmanagergroup.echelon.EchelonLayoutManager;
import com.htyy.yutao.myapplication1.R;

/**
 * Created by Asus on 2018/5/3.
 */

public class View_two extends Fragment{

    private RecyclerView mRecyclerView;
    private EchelonLayoutManager mLayoutManager;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView =  inflater.inflate(R.layout.view_two, container, false);
        mRecyclerView = rootView.findViewById(R.id.recycler_view);
        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    private void initData() {
        mLayoutManager = new EchelonLayoutManager(getContext());
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setAdapter(new MyAdapter());

    }
    class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>{
        private int[] icons = {R.mipmap.header_icon_1,R.mipmap.header_icon_2,R.mipmap.header_icon_3,R.mipmap.header_icon_4};
        private int[] bgs = {R.mipmap.bg_1,R.mipmap.bg_2,R.mipmap.bg_3,R.mipmap.bg_4};
        private String[] nickNames = {"YuTao","于桃","BaoZhu","菜鸟于桃"};
        private String[] descs = {
                "YuTao出品，必属精品",
                "Hybrid小技巧：通过js调用原生对话框(Android)",
                "AngularJs 用户输入动态模板XSS攻击",
                "浅尝flutter中的动画（淡入淡出）",
                "最全面的 Material Design 学习资料",
                "vue：axios二次封装，接口统一存放",
                "五个步骤，成为优秀的前端工程师",
                "基于vue-cli配置移动端自适应项目",
                "学习中使用泛型的一些体会",
                "YuTao出品，必属精品",
                "《小萝莉的猴神大叔》| 罗摩神万岁，那是全部的爱",
                "Vue UI框架库合集",
                "Toolbar的正确使用姿势",
                "关于移动端开发中遇到的坑",
                "手摸手，带你优雅的使用 icon",
                "JS高程中的垃圾回收机制与常见内存泄露的解决方法",
                "Android与物联网设备通信 - 字节报文组装与解析",
                "Android 官方架构组件 Paging：分页库的设计美学",
                "Java：一步步带你深入了解神秘的Java反射机制",
                "YuTao出品，必属精品",
                "Spring Boot + MyBatis + SQLite 基于注解快速开发"

        };
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_echelon,parent,false);
            return new ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, final int position) {
            holder.icon.setImageResource(icons[position%4]);
            holder.nickName.setText(nickNames[position%4]);
            holder.desc.setText(descs[position%5]);
            holder.bg.setImageResource(bgs[position%4]);
        }

        @Override
        public int getItemCount() {
            return 60;
        }

        public class ViewHolder extends RecyclerView.ViewHolder {
            ImageView icon;
            ImageView bg;
            TextView nickName;
            TextView desc;
            public ViewHolder(View itemView) {
                super(itemView);
                icon = itemView.findViewById(R.id.img_icon);
                bg = itemView.findViewById(R.id.img_bg);
                nickName = itemView.findViewById(R.id.tv_nickname);
                desc = itemView.findViewById(R.id.tv_desc);

            }
        }
    }

}
